import { Component, OnInit, Input, OnDestroy } from '@angular/core';

@Component({
  selector: 'app-service-quote',
  templateUrl: './service-quote.component.html',
  styleUrls: ['./service-quote.component.scss'],
})
export class ServiceQuoteComponent implements OnInit, OnDestroy {
  
  @Input() tagData: any;
  checkedService: any;
  paramName: any;
  constructor() { }

  ngOnInit() {
    // this.demoData();
    if (this.tagData.data.data.length > 0) {
      this.tagData.data.data[0].checked = true;
      this.checkedService = this.tagData.data.data[0];
      this.paramName = this.tagData.data.paramName;
      this.saveParam();
    }
  }
  ngOnDestroy() {
    localStorage.removeItem(this.paramName);
  }
  saveParam() {
    if (this.paramName) {
      // delete this.checkedService.checked;
      localStorage.setItem(this.paramName, JSON.stringify(this.checkedService));
    }
  }
  chooseService(obj: any) {
    if (obj.checked) {
      this.checkedService = obj;
      this.saveParam();
      return;
    } else {
      this.tagData.data.data.forEach(element => {
        if (obj === element) {
          element.checked = true;
          this.checkedService = obj;
          this.saveParam();
        } else {
          element.checked = false;
        }
      });
    }
  }

  demoData() {
    this.tagData = {
      type: "tag",
      style: "tag.AppQuotationListTagLogic",
      name: null,
      layout: "body",
      data: {
          data: [
              {
                  price: "1580",
                  type: "转店快",
                  content: "服务1个月"
              },
              {
                  price: "3580",
                  type: "转店快",
                  content: "服务2个月"
              },
              {
                  price: "15800",
                  type: "转店快",
                  content: "服务3个月"
              },
              {
                  price: "32880",
                  type: "转店快",
                  content: "服务4个月"
              }
          ],
          paramName: "quote_id"
      },
          // 标准报价内容
          data1: {
            title: "服务内容",
            subTitle: "开通服务尊享4大超值礼包",
            detailContent: {
              title: "了解详情",
              link: {
                type: "page",
                target: "pageId",
                params: {}
            }
            },
            items: [{
                iconName: "../../../assets/icon/vip_icon_net@3x.png",
                title: "全网推广",
                content: "各大知<br>平台展示;",
                content2: "转让图文广告"
              },
              {
                iconName: "../../../assets/icon/vip_icon_app@3x.png",
                title: "全网推广",
                content: "各大知<br>平台展示;",
                content2: "转让图文广告"
              },
              {
                iconName: "../../../assets/icon/vip_icon_ai@3x.png",
                title: "全网推广",
                content: "各大知<br>平台展示;",
                content2: ""
              },
              {
                iconName: "../../../assets/icon/vip_icon_vip@3x.png",
                title: "全网推广",
                content: "各大知\t\n平台展示;",
                content2: "转让图文广告"
              }
            ]
        }
    };
  }
}

// {
//   "type": "tag",
//   "style": "xxxx",
//   "name": "xxxx",
//   "layout":"body | footer 默认为body",
//   "data": {
//       "action": "link | submit",
//       "paramName": "string,string",
//       "label": "确认购买",
//       "cssStyle":"orange | brown",
//       "submit": {
//           "id": "string",
//           "content": {
//               "serviceId": "string"
//           }
//       },
//       "link": {
//           "type": "page",
//           "target": "pageId",
//           "params": {}
//       }
//   }
// }


//       // 业务员报价
//       salesmanQuotation: {
//         // 预付
//         prepaidPrice: {
//           price: "￥2000",
//           title: "预付金额",
//         },
//         servicePrice: {
//           price: "￥35000",
//           title: "服务价格",
//           describe: "支付预付金额即可开通服务，服务结束后再支付剩余款项"
//         },
//         serviceType: {
//           title: "服务类型",
//           content: "转店快服务",
//         },
//         serviceContent: {
//           title: "服务内容",
//           items: [ {
//             title: "服务时长",
//             content: "服务35天",
//           },
//           {
//             title: "广告位",
//             content: "PC转店焦点广告，展示30天",
//           } ],
//         },
//       },
//      };
//   }
// }
